<?php
/**
 * redis本系统扩展
 */

namespace App\Libs;

class RedisLib
{
    /** @var int 注册功能-邮件限制次数 */
    static public $register_email_limit = 5;

    /** @var string 注册功能-邮件发送次数缓存前缀 */
    static public $register_email_prefix = 'register_email_';

    /** @var string 注册功能-密码的key */
    static public $register_account_key = 'register_account_key_';

    /** @var int 忘记密码-邮件限制次数 */
    static public $forget_email_limit = 5;

    /** @var string 忘记密码-邮件发送次数缓存前缀 */
    static public $forget_email_prefix = 'forget_email_';

    /** @var string 忘记功能-密码的key */
    static public $forget_account_key = 'forget_account_key_';

    /**
     * 获取邮件场景的redis缓存key
     * @param $type
     * @param $email
     * @return string
     */
    static public function getEmailRedisKey($type, $email)
    {
        switch ($type) {
            case 1:// 邮件注册发送次数
                return self::$register_email_prefix  . $email;
            case 2:// 邮件忘记密码发送次数
                return self::$forget_email_prefix . $email;
            case 3:// 注册验证密码缓存
                return self::$register_account_key . $email;
            case 4:// 忘记密码缓存
                return self::$forget_account_key . $email;
        }
    }

    /**
     * 获取图形验证码 缓存 key
     * @param $sceneType
     * @return string
     */
    static public function getCaptchaKey($sceneType)
    {
        $sceneTypeMap = [
            0 => 'common',
            1 => 'register',
            2 => 'forget',
        ];
        return $sceneTypeMap[$sceneType] . '_clicaptcha_text_' . session()->getId();
    }
}
